#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int widthOfBinaryTree(TreeNode* root) {
        queue<pair<TreeNode*, unsigned int>> q;
        q.push({ root, 1 });
        unsigned int ret = 0;
        while (q.size()) {
            int sz = q.size();
            auto& [x1, y1] = q.front();
            auto& [x2, y2] = q.back();
            ret = max(ret, (y2 - y1 + 1));

            for (int i = 0; i < sz; i++) {
                auto& [m, n] = q.front();

                if (m->left) q.push({ m->left,2 * n });
                if (m->right) q.push({ m->right,2 * n + 1 });
                q.pop();
            }
        }
        return ret;
    }
};